//类的组合:线段Segment类中的两个属性m_pointB、m_pointA，是点Point类对象
//请注意构造函数的调用顺序，分析下m_pointB、m_pointA的构造顺序
#include <iostream>
#include<cmath>
using namespace std;
class Point //点
{
public:
    Point(float x, float y) : m_x(x), m_y(y)
    {
        cout<<"Point Con, the point is ";
        this->print();
        cout<<endl;
    }
    float distances(const Point& other)const
    {
        float dstn;
        dstn=(m_x-other.m_x)*(m_x-other.m_x)+(m_y-other.m_y)*(m_y-other.m_y);
        return sqrt(dstn);
    }
    void print() const
    {
        cout<<"("<<m_x<<" , "<<m_y<<")";
    }
private:
    float m_x, m_y;
};

class Segment //线段
{
public:
    Segment(Point A, Point B) : m_pointA(A), m_pointB(B)
    {
        cout<<"Segment Con1 "<<endl;
    }
    Segment(float x1, float y1, float x2, float y2) : m_pointA(x1, y1), m_pointB(x2, y2)
    {
         cout<<"Segment Con2 "<<endl;
    }
    void print() const
    {
        m_pointA.print();
        cout<<" ---> ";
        m_pointB.print();
    }
    float length()const
    {
        return m_pointA.distances(m_pointB);
    }
private:
    Point m_pointB;
    Point m_pointA;
};

int main()
{
    Point pa(4, 6), pb(3, 5); 
    Segment seg1(pa, pb);     
    Segment seg2(-1, -2, -10, -20);//请分析m_pointA、m_pointB的构造顺序
    cout<<"seg1 len="<<seg1.length()<<endl;
    cout<<"seg2 len="<<seg2.length()<<endl;
    return 0;
}